#include <stdio.h>
#include <string.h> // memcpy
#include <malloc.h> // malloc
#include <stdbool.h> // bool


// typedef !!
typedef struct {
    long long * balance;
    int balanceSize;
} Bank;

Bank* bankCreate(long long* balance, int balanceSize) {
    Bank * obj = (Bank *)malloc(sizeof(Bank));
    // malloc 动态分配内存？？
    obj->balance = (long long *)malloc(sizeof(long long) * balanceSize);
    obj->balanceSize = balanceSize;
    // memcpy 给balance赋值？？更新balance的值？？
    memcpy(obj->balance, balance, sizeof(long long) * balanceSize);
    return obj;
}


bool bankTransfer(Bank* obj, int account1, int account2, long long money) {
    if (account1 > obj->balanceSize || account2 > obj->balanceSize || obj->balance[account1 - 1] < money) {
        return false;
    }
    obj->balance[account1 - 1] -= money;
    obj->balance[account2 - 1] += money;
    return true;
}

bool bankDeposit(Bank* obj, int account, long long money) {
    if (account > obj->balanceSize) {
        return false;
    }
    obj->balance[account - 1] += money;
    return true;
}

bool bankWithdraw(Bank* obj, int account, long long money) {
    if (account > obj->balanceSize || obj->balance[account - 1] < money) {
        return false;
    }
    obj->balance[account - 1] -= money;
    return true;
}

void bankFree(Bank* obj) {
    // free 释放 
    free(obj->balance);
}

// c语言的输入不知道何时才能明白喽？？？
